﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Data.Entity.Validation;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using NhaThuocOnline.Entities;
namespace NhaThuocOnline.Repositories
{
    public class DonViTinhRepository:IDisposable
    {
        QLNhathuocContext context = new QLNhathuocContext();
        public void InsertOrUpdate(DonViTinh dvt)
        {
            if (dvt.Id == default(int))
            {
                context.DonViTinhs.Add(dvt);
            }
            else
            {
                context.Entry(dvt).State = EntityState.Modified;
            }
        }
        public void Delete(int id)
        {
            DonViTinh dvt = context.DonViTinhs.Find(id);
            context.DonViTinhs.Remove(dvt);
        }
        public void Save()
        {
            context.SaveChanges();
        }
        public void Dispose()
        {
            context.Dispose();
        }
        public DonViTinh Find(int id)
        {
            return context.DonViTinhs.Find(id);
        }
        public IQueryable<DonViTinh> GetAll
        {
            get { return context.DonViTinhs; }
        }
    }
}
